package com.pylc.model.entity;

import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import java.util.Set;

/**
 * @author Lindsey
 */
@Entity
@Table
public class StoreCategory extends BaseEntity {
    private String name;
    private Integer sortOrder;
    private StoreCategory parent;
    private Integer depth;
    private Set<StoreCategory> children;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name="parent_id")
    @Cascade(value = { org.hibernate.annotations.CascadeType.DELETE })
    @OrderBy("sortOrder asc")
    public Set<StoreCategory> getChildren() {
        return children;
    }

    public void setChildren(Set<StoreCategory> children) {
        this.children = children;
    }

    @Column
    public Integer getDepth() {
        return depth;
    }

    public void setDepth(Integer depth) {
        this.depth = depth;
    }

    @Column
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="parent_id")
    public StoreCategory getParent() {
        return parent;
    }

    public void setParent(StoreCategory parent) {
        this.parent = parent;
    }

    @Column
    public Integer getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }
}
